@extends('admin.layout')
@section('content')
  <!-- Content Wrapper. Contains page content -->
    <div class="content-wrapper">
        <!-- Content Header (Page header) -->
        <section class="content-header">
            <h1>
                内容管理
                <small>列表</small>
            </h1>
            <ol class="breadcrumb">
                <li><a href="#"><i class="fa fa-dashboard"></i> 主页</a></li>
                <li><a href="#">内容管理</a></li>
                <li class="active">列表</li>
            </ol>
        </section>

        <!-- Main content -->
        <section class="content">
            <div class="row">
                <div class="col-xs-12">
                    <div class="box">
                        <div class="box-header">
                            <h3 class="box-title">快速查看内容</h3>
                    @if(session('info'))
                            <div class="alert alert-success alert-dismissable">
                                <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                                <h4><i class="icon fa fa-warning"></i> 警告!</h4>
                                 <ul>
                                    {{ session('info') }}
                                 </ul>
                                </div>                              
                            @endif  
                        </div><!-- /.box-header -->
                       	
                        <div class="box-body">
                        <form action="{{ url('/admin/goods/index') }}" method='get'>	

							<div class='row'>
								<div class='col-md-4'>
									<div class="form-group">
                                   
                                    <select name='num' class="form-control">
                                        <option 
											@if(!empty($request['num']) && $request['num']== 10)
											selected = 'selected'
											@endif
                                        value='10'>10</option>
                                        <option 
                                        	@if(!empty($request['num']) && $request['num'] == 15)
											selected = 'selected'
											@endif
											value='15'>15</option>
                                        <option
											@if(!empty($request['num']) && $request['num'] == 25)
											selected = 'selected'
											@endif
                                        value='25'>25</option>
                                        <option 
											@if(!empty($request['num']) && $request['num'] == 50)
											selected = 'selected'
											@endif
                                        value='50'>50</option>
                                        <option 
											@if(!empty($request['num']) && $request['num'] == 100)
											selected = 'selected'
											@endif		
                                        value='100'>100</option>
                                    </select>
                                </div>

								</div>
								<div class='col-md-4 col-md-offset-4'>
									
		                       		<div class="input-group input-group-sm">
		                                <input value="{{ $request['keywords'] or ''}}" name='keywords' type="text" class="form-control">
					                    <span class="input-group-btn">
					                      <button class="btn btn-info btn-flat">搜索</button>
					                    </span>
				                    </div>
								</div>
							</div>

						</form>
                            <table id="example2" class="table table-bordered table-hover">
                                <thead>
	                                <tr>
	                                    <th>Id</th>
	                                    <th>头部图片</th>
	                                    
	                                    <th class='name'>标题</th>
	                                    
	                                    <th>内容分类</th>
	                                    
	                                   
	                                    <th>发布时间</th>
	                                    <th>首页显示样式</th>
	                                    <th>状态</th>
	                                    <th>操作</th>
	                                </tr>
                                </thead>
                                @foreach($data as $goods)
                                <tbody>
	                                <tr>
	                                    <td class='ids'>{{ $goods -> id }}</td>
	                                    <td><img style='width:80px' src="{{ url('/uploads') }}/{{ $goods -> img_head }}"></th>
	                                    <td>{{ $goods -> title }}</td>
	                                   
	                                    <td>{{ $goods -> cname}}</td>
	                                    <td>{{ $goods -> time }}</td>
	                                    <td>
	                                    	@if($goods -> zstyle == 0)
		                                    小黑方块（占1列）
		                                    @elseif($goods -> zstyle == 1)
		                                    中型方块（占2列）
		                                    @elseif($goods -> zstyle == 2)
		                                    小白方块（占1列）
		                                    @elseif($goods -> zstyle == 3)
		                                    大方块（占3列）
		                                    @endif
	                                    </td>
	                                    
	                                    <td class='status'>
	                                    @if($goods -> status == 0)
	                                    审核通过
	                                    @else
	                                    未审核
	                                    @endif
	                                    </td>
	                               
	                                    <td><a href="{{ url('/admin/goods/content') }}/{{ $goods -> id }}">查看内容</a>|<a href="{{ url('/admin/goods/edit') }}/{{ $goods -> id }}">编辑</a>|<a href="{{ url('/admin/goods/delete') }}/{{ $goods -> id }}">删除</a></td>
	                                </tr>

                                </tbody>
								@endforeach

							
                            </table>
                            	{!! $data ->appends($request) -> render() !!}
                        </div><!-- /.box-body -->
                    </div><!-- /.box -->
                </div><!-- /.col -->
            </div><!-- /.row -->
        </section><!-- /.content -->
    </div><!-- /.content-wrapper -->
    <script type="text/javascript">
    	window.onload = function()
    	{
    		//修改状态
    		$.ajaxSetup({
			    headers: {
			    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
	  			}
			});
			$('.status').on('click', function()
			{
				var id = $(this).parent().find('.ids').html();
				// alert(id);
				var t = $(this);
				$.ajax({
					url:"{{ url('/admin/goods/ajaxupdate') }}",
					type:'POST',
					data:{'id':id},
					success:function(data)
					{
						if(data == '0')
						{
							t.html('审核通过');
						}else if(data == '1')
						{
							t.html('未审核');
						}else
						{
							alert('修改失败');
						}
						
					},
					dataType:'json'
				});	
			});
			$('.status').on('mouseover', function()
			{
				this.style.cursor = 'pointer';
				this.style.color= 'red';
			});
			$('.status').on('mouseout', function()
			{
				
				this.style.color= 'black';

			});


			function dblclick()
			{

				var id = $(this).parent().find('.ids').html();
				var t = $(this);
				//获取旧文件名
				var oldTitle = $(this).html();

				//获取input
				var inp = $("<input type='text' />");

				inp.val(oldName);
				// dd(inp);
				$(this).html(inp);
				//获取焦点事件
				inp.select();

				//失去焦点事件
				inp.on('blur', function(){
					//获取新值
					var newTitle = inp.val();
					// alert(222);
					//书写ajax
					$.ajax({
						url:"{{ url('/admin/goods/ajaxName') }}",
						type:'POST',
						data:{id:id, title:newTitle},
						success:function(data)
						{

							if(data == '0')
							{
								t.html(newtitle);
								
							}else if(data == '1')
							{
								t.html(oldTitle);
							}else
							{
								t.html(oldTitle);
								alert('内容名已存在');
							}
						}
					

					});	
					t.on('dblclick',dblclick);
				});	
				//清除双击事件
				t.unbind('dblclick');

			}
			//修改内容名
			$('.name').on('dblclick', dblclick);
    	}
    	
    </script>
@endsection('content')